name = "moisture persentage (%)"
)+
scale_y_continuous(
expand = c(0,0),
limits = c(0,50),
name = NULL
)+
stat_poly_eq(use_label("eq")) +
stat_poly_eq(label.y = 0.9)+
my_theme+
labs(title = "Fe")+
theme(legend.position = "null")
p3<-wrangled_data%>%
filter(element=="Pb")%>%
ggplot(aes(
x=moisture_persentage,
y=sample_persentage_change_v2,
))+
geom_point(aes(color=matrix,shape=Depth))+
geom_smooth(method = lm,color="#616161",se = FALSE)+
geom_abline(aes(intercept=0, slope=1),linetype="dashed",)+
facet_grid(rows = vars(matrix),cols = vars(Depth),scales = "free")+
scale_x_continuous(
expand = c(0,0),
limits = c(0,50),
name = NULL
)+
scale_y_continuous(
expand = c(0,0),
limits = c(0,50),
name = NULL
)+
stat_poly_eq(use_label("eq")) +
stat_poly_eq(label.y = 0.9)+
my_theme+
labs(title = "Pb")+
theme(legend.position = "null")
p1+p2+p3
ggsave("Fig_E_H20_persentage_v2_faceted.png", width = 280, height = 180, units = "mm") #custom
library(tidyverse)
library(patchwork)
library(cowplot)
library(scales)
library(ggpmisc)
library(tidymodels)
library(RColorBrewer)
#my functons============
transpose_tibble<-function(tibble){
tibble%>%
rename(rowname=1)%>%
mutate(across(everything(),~as.character(.)))%>%
pivot_longer(cols = !rowname ,names_to = 'variable',  values_to = 'value') %>%
pivot_wider(id_cols = variable, names_from = rowname, values_from = value)%>%
type.convert(as.is=TRUE)
}
my_theme<-theme_light()+
theme(
strip.background = element_blank(),
panel.spacing.x = unit(.75, "lines"),
panel.spacing.y = unit(0, "lines"),
panel.border = element_rect(color= "black"),
#legend.position = "none",
#plot.margin = margin(t = c(0.2, 0.2, 0.2, 0.2) , unit = "cm"),
axis.ticks = element_line(color = "black"),
axis.text.x = element_text(angle = 45, hjust = 1),
text = element_text(size = 9,
color = "black",
family = "Arial"),
plot.title = element_text(face = "bold", size = 10),
strip.text = element_text(hjust = 0,
face = "bold",
size = 10,
color = "black"),
)
setwd("C:/Users/s299038/OneDrive - Cranfield University/1. Rapid Measurement Tools - Niall/Chapter 3 - XRF Analysis Accuracy on Slag/Data Analysis/Fig_E OM and moistuer corrilation/source data")
a_H2O<-read_csv("1.mass_change_H2O.csv")
b_OM<-read_csv("2.mass_change_OM.csv")
setwd("C:/Users/s299038/OneDrive - Cranfield University/1. Rapid Measurement Tools - Niall/Chapter 3 - XRF Analysis Accuracy on Slag/Data Analysis/Fig_E OM and moistuer corrilation")
setwd("C:/Users/s299038/OneDrive - Cranfield University/1. Rapid Measurement Tools - Niall/Chapter 3 - XRF Analysis Accuracy on Slag/Data Analysis/combining for analysis")
pivoted_data<-read_csv("filterd_data.csv")
setwd("C:/Users/s299038/OneDrive - Cranfield University/1. Rapid Measurement Tools - Niall/Chapter 3 - XRF Analysis Accuracy on Slag/Data Analysis/Fig_E OM and moistuer corrilation")
a1_H2O<-a_H2O%>%mutate(dry_mass=`dry mass+tin` - `tin mass (g)`,
wet_mass=`wet mass+tin` - `tin mass (g)`,
moisture_mass=wet_mass - dry_mass,
moisture_persentage=( (wet_mass - dry_mass) / dry_mass) * 100)
a2_H2O<-a1_H2O%>%select(wet_mass,dry_mass,moisture_persentage,ID)
b1_OM<-b_OM%>%mutate(dried=`crucible +dried` - `crucible wheight`,
ignited= `crucible + ignited sample` - `crucible wheight`,
organic_matter= dried - ignited,
organic_matter_persentage =( (dried - ignited) / ignited) * 100)
b2_OM<-b1_OM%>%select(dried,ignited,organic_matter_persentage,ID)%>%
rename(dry_mass=dried,ignited_mass=ignited)
wrangled_data<-pivoted_data%>%
filter(Prosessing_Step%in%c("sived","dried","ICP"))%>%
pivot_wider(id_cols = ID:element,names_from = Prosessing_Step,values_from = mean)%>%
filter(element%in%c("Fe","Ca","Pb"))%>%
inner_join(a2_H2O,by="ID")%>%
mutate(
Depth = ifelse(Depth == 1, "surface", "subsurface"),
corrected = (sived * wet_mass) / dry_mass,
corrected_v2 = sived * (1 + (moisture_persentage/100)),
sample_persentage_change =( (dried - sived) / dried ) * 100,
sample_persentage_change_v2 =-( (sived - dried) / sived ) * 100,
correction_persentage_change_v1 =( (corrected - sived) / corrected ) * 100
)
#shuttleworth method====
wrangled_data%>%ggplot(aes(x=corrected,y=dried))+
geom_point(aes(color=Depth,shape=matrix))+
geom_smooth(method=lm,color="#616161",se = FALSE)+
facet_wrap(vars(element),scales = "free")+
geom_abline(aes(intercept=0, slope=1),linetype="dashed",)+
stat_poly_eq(use_label("eq")) +
stat_poly_eq(label.y = 0.9)+
#geom_point(aes(shape=matrix,x=sived),color="black")+
my_theme+
scale_x_continuous(labels = comma_format(),
expand = c(0, 0),
limits = c(0, NA))+
scale_y_continuous(labels = comma_format(),
expand = c(0, 0),
limits = c(0, NA))+
theme(legend.position = "bottom")+
labs(x = "sived pXRF measurment corrected by shuttleworth et al (mg/kg)", y = "dried pXRF measurment (mg/kg)")
#persentage method ====
wrangled_data%>%
ggplot(aes(x=moisture_persentage,y=sample_persentage_change))+
geom_point(aes(color=Depth,shape=matrix))+
geom_smooth(method=lm,color="#616161",se = FALSE)+
facet_wrap(vars(element))+
scale_x_continuous(expand = c(0,0),
limits = c(0,50),
name = "Moisture (%)")+
scale_y_continuous(expand = c(0,0),
limits = c(0,50),
name = "Change in pXRF Meansurment After Drying (%)")+
geom_abline(aes(intercept=0, slope=1),linetype="dashed",)+
stat_poly_eq(use_label("eq")) +
stat_poly_eq(label.y = 0.9)+
my_theme+
theme(legend.position = "bottom")
#persentage method_v2====
wrangled_data%>%
ggplot(aes(x=moisture_persentage,y=sample_persentage_change_v2))+
geom_point(aes(color=Depth,shape=matrix))+
geom_smooth(method=lm,color="#616161",se = FALSE)+
facet_wrap(vars(element))+
scale_x_continuous(expand = c(0,0),
limits = c(0,50),
name = "Moisture (%)")+
scale_y_continuous(expand = c(0,0),
limits = c(0,50),
name = "Change in pXRF Meansurment After Drying (%)")+
geom_abline(aes(intercept=0, slope=1),linetype="dashed",)+
stat_poly_eq(use_label("eq")) +
stat_poly_eq(label.y = 0.9)+
my_theme+
theme(legend.position = "bottom")
a1_H2O<-a_H2O%>%mutate(dry_mass=`dry mass+tin` - `tin mass (g)`,
wet_mass=`wet mass+tin` - `tin mass (g)`,
moisture_mass=wet_mass - dry_mass,
moisture_persentage=( (wet_mass - dry_mass) / dry_mass) * 100) # corrected
a2_H2O<-a1_H2O%>%select(wet_mass,dry_mass,moisture_persentage,ID)
b1_OM<-b_OM%>%mutate(dried=`crucible +dried` - `crucible wheight`,
ignited= `crucible + ignited sample` - `crucible wheight`,
organic_matter= dried - ignited,
organic_matter_persentage =( (dried - ignited) / dried) * 100) #corrected
b2_OM<-b1_OM%>%select(dried,ignited,organic_matter_persentage,ID)%>%
rename(dry_mass=dried,ignited_mass=ignited)
wrangled_data<-pivoted_data%>%
filter(Prosessing_Step%in%c("sived","dried","ICP"))%>%
pivot_wider(id_cols = ID:element,names_from = Prosessing_Step,values_from = mean)%>%
filter(element%in%c("Fe","Ca","Pb"))%>%
inner_join(a2_H2O,by="ID")%>%
mutate(
Depth = ifelse(Depth == 1, "surface", "subsurface"),
corrected = (sived * wet_mass) / dry_mass,
corrected_v2 = sived * (1 + (moisture_persentage/100)),
sample_persentage_change =( (dried - sived) / dried ) * 100,
sample_persentage_change_v2 =-( (sived - dried) / sived ) * 100,
sample_persentage_change_v3 =-( (dried - sived) / dried ) * 100,
correction_persentage_change_v1 =( (corrected - sived) / corrected ) * 100
)
#persentage method_v3====
wrangled_data%>%
ggplot(aes(x=moisture_persentage,y=sample_persentage_change_v3))+
geom_point(aes(color=Depth,shape=matrix))+
geom_smooth(method=lm,color="#616161",se = FALSE)+
facet_wrap(vars(element))+
scale_x_continuous(expand = c(0,0),
limits = c(0,50),
name = "Moisture (%)")+
scale_y_continuous(expand = c(0,0),
limits = c(0,50),
name = "Change in pXRF Meansurment After Drying (%)")+
geom_abline(aes(intercept=0, slope=1),linetype="dashed",)+
stat_poly_eq(use_label("eq")) +
stat_poly_eq(label.y = 0.9)+
my_theme+
theme(legend.position = "bottom")
View(wrangled_data)
wrangled_data<-pivoted_data%>%
filter(Prosessing_Step%in%c("sived","dried","ICP"))%>%
pivot_wider(id_cols = ID:element,names_from = Prosessing_Step,values_from = mean)%>%
filter(element%in%c("Fe","Ca","Pb"))%>%
inner_join(a2_H2O,by="ID")%>%
mutate(
Depth = ifelse(Depth == 1, "surface", "subsurface"),
corrected = (sived * wet_mass) / dry_mass,
corrected_v2 = sived * (1 + (moisture_persentage/100)),
sample_persentage_change =( (dried - sived) / dried ) * 100,
sample_persentage_change_v2 =-( (sived - dried) / sived ) * 100,
sample_persentage_change_v3 =( (dried - sived) / dried ) * 100,
correction_persentage_change_v1 =( (corrected - sived) / corrected ) * 100
)
#persentage method_v3====
wrangled_data%>%
ggplot(aes(x=moisture_persentage,y=sample_persentage_change_v3))+
geom_point(aes(color=Depth,shape=matrix))+
geom_smooth(method=lm,color="#616161",se = FALSE)+
facet_wrap(vars(element))+
scale_x_continuous(expand = c(0,0),
limits = c(0,50),
name = "Moisture (%)")+
scale_y_continuous(expand = c(0,0),
limits = c(0,50),
name = "Change in pXRF Meansurment After Drying (%)")+
geom_abline(aes(intercept=0, slope=1),linetype="dashed",)+
stat_poly_eq(use_label("eq")) +
stat_poly_eq(label.y = 0.9)+
my_theme+
theme(legend.position = "bottom")
#persentage method ====
wrangled_data%>%
ggplot(aes(x=moisture_persentage,y=sample_persentage_change))+
geom_point(aes(color=Depth,shape=matrix))+
geom_smooth(method=lm,color="#616161",se = FALSE)+
facet_wrap(vars(element))+
scale_x_continuous(expand = c(0,0),
limits = c(0,50),
name = "Moisture (%)")+
scale_y_continuous(expand = c(0,0),
limits = c(0,50),
name = "Change in pXRF Meansurment After Drying (%)")+
geom_abline(aes(intercept=0, slope=1),linetype="dashed",)+
stat_poly_eq(use_label("eq")) +
stat_poly_eq(label.y = 0.9)+
my_theme+
theme(legend.position = "bottom")
#persentage method_v2====
wrangled_data%>%
ggplot(aes(x=moisture_persentage,y=sample_persentage_change_v2))+
geom_point(aes(color=Depth,shape=matrix))+
geom_smooth(method=lm,color="#616161",se = FALSE)+
facet_wrap(vars(element))+
scale_x_continuous(expand = c(0,0),
limits = c(0,50),
name = "Moisture (%)")+
scale_y_continuous(expand = c(0,0),
limits = c(0,50),
name = "Change in pXRF Meansurment After Drying (%)")+
geom_abline(aes(intercept=0, slope=1),linetype="dashed",)+
stat_poly_eq(use_label("eq")) +
stat_poly_eq(label.y = 0.9)+
my_theme+
theme(legend.position = "bottom")
#persentage method_v3====
wrangled_data%>%
ggplot(aes(x=moisture_persentage,y=sample_persentage_change_v3))+
geom_point(aes(color=Depth,shape=matrix))+
geom_smooth(method=lm,color="#616161",se = FALSE)+
facet_wrap(vars(element))+
scale_x_continuous(expand = c(0,0),
limits = c(0,50),
name = "Moisture (%)")+
scale_y_continuous(expand = c(0,0),
limits = c(0,50),
name = "Change in pXRF Meansurment After Drying (%)")+
geom_abline(aes(intercept=0, slope=1),linetype="dashed",)+
stat_poly_eq(use_label("eq")) +
stat_poly_eq(label.y = 0.9)+
my_theme+
theme(legend.position = "bottom")
wrangled_data<-pivoted_data%>%
filter(Prosessing_Step%in%c("sived","dried","ICP"))%>%
pivot_wider(id_cols = ID:element,names_from = Prosessing_Step,values_from = mean)%>%
filter(element%in%c("Fe","Ca","Pb"))%>%
inner_join(a2_H2O,by="ID")%>%
mutate(
Depth = ifelse(Depth == 1, "surface", "subsurface"),
corrected = (sived * wet_mass) / dry_mass,
corrected_v2 = sived * (1 + (moisture_persentage/100)),
sample_persentage_change =( (dried - sived) / dried ) * 100, #this with the correct moisture calc is correct.
sample_persentage_change_v2 =-( (sived - dried) / sived ) * 100,
attenuation_schneider= sived/dried
correction_persentage_change_v1 =( (corrected - sived) / corrected ) * 100
wrangled_data<-pivoted_data%>%
filter(Prosessing_Step%in%c("sived","dried","ICP"))%>%
pivot_wider(id_cols = ID:element,names_from = Prosessing_Step,values_from = mean)%>%
filter(element%in%c("Fe","Ca","Pb"))%>%
inner_join(a2_H2O,by="ID")%>%
mutate(
Depth = ifelse(Depth == 1, "surface", "subsurface"),
corrected = (sived * wet_mass) / dry_mass,
corrected_v2 = sived * (1 + (moisture_persentage/100)),
sample_persentage_change =( (dried - sived) / dried ) * 100, #this with the correct moisture calc is correct.
sample_persentage_change_v2 =-( (sived - dried) / sived ) * 100,
attenuation_schneider= sived/dried,
correction_persentage_change_v1 =( (corrected - sived) / corrected ) * 100
)
#schnider plots====
wrangled_data%>%
ggplot(aes(x=moisture_persentage,y=attenuation_schneider))+
geom_point(aes(color=Depth,shape=matrix))+
geom_smooth(method=lm,color="#616161",se = FALSE)+
facet_wrap(vars(element))+
scale_x_continuous(expand = c(0,0),
limits = c(0,50),
name = "Moisture (%)")+
scale_y_continuous(expand = c(0,0),
limits = c(0,50),
name = "Change in pXRF Meansurment After Drying (%)")+
geom_abline(aes(intercept=0, slope=1),linetype="dashed",)+
stat_poly_eq(use_label("eq")) +
stat_poly_eq(label.y = 0.9)+
my_theme+
theme(legend.position = "bottom")
#schnider plots====
wrangled_data%>%
ggplot(aes(x=moisture_persentage,y=attenuation_schneider))+
geom_point(aes(color=Depth,shape=matrix))+
geom_smooth(method=lm,color="#616161",se = FALSE)+
facet_wrap(vars(element))+
scale_x_continuous(expand = c(0,0),
limits = c(0,50),
name = "Moisture (%)")+
#scale_y_continuous(expand = c(0,0),
#   limits = c(0,50),
#    name = "Change in pXRF Meansurment After Drying (%)")+
geom_abline(aes(intercept=0, slope=1),linetype="dashed",)+
stat_poly_eq(use_label("eq")) +
stat_poly_eq(label.y = 0.9)+
my_theme+
theme(legend.position = "bottom")
#schnider plots====
wrangled_data%>%
ggplot(aes(x=moisture_persentage,y=attenuation_schneider))+
geom_point(aes(color=Depth,shape=matrix))+
geom_smooth(method=lm,color="#616161",se = FALSE)+
facet_wrap(vars(element))+
scale_x_continuous(expand = c(0,0),
limits = c(0,50),
name = "Moisture (%)")+
#scale_y_continuous(expand = c(0,0),
#   limits = c(0,50),
#    name = "Change in pXRF Meansurment After Drying (%)")+
#geom_abline(aes(intercept=0, slope=1),linetype="dashed",)+
#stat_poly_eq(use_label("eq")) +
#stat_poly_eq(label.y = 0.9)+
my_theme+
theme(legend.position = "bottom")
View(wrangled_data)
View(wrangled_data)
wrangled_data<-pivoted_data%>%
filter(Prosessing_Step%in%c("sived","dried","ICP"))%>%
pivot_wider(id_cols = ID:element,names_from = Prosessing_Step,values_from = mean)%>%
#filter(element%in%c("Fe","Ca","Pb"))%>%
inner_join(a2_H2O,by="ID")%>%
mutate(
Depth = ifelse(Depth == 1, "surface", "subsurface"),
corrected = (sived * wet_mass) / dry_mass,
corrected_v2 = sived * (1 + (moisture_persentage/100)),
sample_persentage_change =( (dried - sived) / dried ) * 100, #this with the correct moisture calc is correct.
sample_persentage_change_v2 =-( (sived - dried) / sived ) * 100,
attenuation_schneider= sived/dried,
correction_persentage_change_v1 =( (corrected - sived) / corrected ) * 100
)
#schnider plots====
wrangled_data%>%
ggplot(aes(x=moisture_persentage,y=attenuation_schneider))+
geom_point(aes(color=Depth,shape=matrix))+
geom_smooth(method=lm,color="#616161",se = FALSE)+
facet_wrap(vars(element))+
scale_x_continuous(expand = c(0,0),
limits = c(0,50),
name = "Moisture (%)")+
#scale_y_continuous(expand = c(0,0),
#   limits = c(0,50),
#    name = "Change in pXRF Meansurment After Drying (%)")+
#geom_abline(aes(intercept=0, slope=1),linetype="dashed",)+
#stat_poly_eq(use_label("eq")) +
#stat_poly_eq(label.y = 0.9)+
my_theme+
theme(legend.position = "bottom")
#schnider plots====
wrangled_data%>%
ggplot(aes(x=moisture_persentage,y=attenuation_schneider))+
geom_point(aes(color=Depth,shape=matrix))+
geom_smooth(method=lm,color="#616161",se = FALSE)+
facet_wrap(vars(element))+
scale_x_continuous(expand = c(0,0),
limits = c(0,50),
name = "Moisture (%)")+
scale_y_continuous(expand = c(0,0),
limits = c(0,1.5),
name = "Cwet/Cdry")+
#geom_abline(aes(intercept=0, slope=1),linetype="dashed",)+
#stat_poly_eq(use_label("eq")) +
#stat_poly_eq(label.y = 0.9)+
my_theme+
theme(legend.position = "bottom")
#schnider plots====
wrangled_data%>%
ggplot(aes(x=moisture_persentage,y=attenuation_schneider))+
geom_point(aes(color=Depth,shape=matrix))+
geom_smooth(method=lm,color="#616161",formula = y ~ poly(x, 2), se = FALSE)+
facet_wrap(vars(element))+
scale_x_continuous(expand = c(0,0),
limits = c(0,50),
name = "Moisture (%)")+
scale_y_continuous(expand = c(0,0),
limits = c(0,1.5),
name = "Cwet/Cdry")+
#geom_abline(aes(intercept=0, slope=1),linetype="dashed",)+
#stat_poly_eq(use_label("eq")) +
#stat_poly_eq(label.y = 0.9)+
my_theme+
theme(legend.position = "bottom")
#schnider plots====
wrangled_data%>%
ggplot(aes(x=moisture_persentage,y=attenuation_schneider))+
geom_point(aes(color=Depth,shape=matrix))+
geom_smooth(method=lm,color="#616161",formula = y ~ poly(x, 2))+
facet_wrap(vars(element))+
scale_x_continuous(expand = c(0,0),
limits = c(0,50),
name = "Moisture (%)")+
scale_y_continuous(expand = c(0,0),
limits = c(0,1.5),
name = "Cwet/Cdry")+
#geom_abline(aes(intercept=0, slope=1),linetype="dashed",)+
#stat_poly_eq(use_label("eq")) +
#stat_poly_eq(label.y = 0.9)+
my_theme+
theme(legend.position = "bottom")
#schnider plots====
wrangled_data%>%
ggplot(aes(x=moisture_persentage,y=attenuation_schneider))+
geom_point(aes(color=Depth,shape=matrix))+
geom_smooth(method=lm,color="#616161",formula = y ~ poly(x, 2))+
facet_wrap(vars(element))+
scale_x_continuous(expand = c(0,0),
limits = c(0,100),
name = "Moisture (%)")+
scale_y_continuous(expand = c(0,0),
limits = c(0,1.2),
name = "Cwet/Cdry")+
#geom_abline(aes(intercept=0, slope=1),linetype="dashed",)+
#stat_poly_eq(use_label("eq")) +
#stat_poly_eq(label.y = 0.9)+
my_theme+
theme(legend.position = "bottom")
#schnider plots====
wrangled_data%>%
ggplot(aes(x=moisture_persentage,y=attenuation_schneider))+
geom_point(aes(color=Depth,shape=matrix))+
geom_smooth(method=lm,color="#616161",formula = y ~ poly(x, 2))+
facet_wrap(vars(element))+
scale_x_continuous(expand = c(0,0),
limits = c(0,100),
name = "Moisture (%)")+
scale_y_continuous(expand = c(0,0),
limits = c(0,1),
name = "Cwet/Cdry")+
#geom_abline(aes(intercept=0, slope=1),linetype="dashed",)+
#stat_poly_eq(use_label("eq")) +
#stat_poly_eq(label.y = 0.9)+
my_theme+
theme(legend.position = "bottom")
#schnider plots====
wrangled_data%>%
ggplot(aes(x=moisture_persentage,y=attenuation_schneider))+
geom_point(aes(color=Depth,shape=matrix))+
geom_smooth(method=lm,color="#616161",formula = y ~ poly(x, 2))+
facet_wrap(vars(element))+
scale_x_continuous(expand = c(0,0),
limits = c(0,100),
name = "Moisture (%)")+
scale_y_continuous(expand = c(0,0),
limits = c(0,1),
name = "Cwet/Cdry")+
#geom_abline(aes(intercept=0, slope=1),linetype="dashed",)+
#stat_poly_eq(use_label("eq")) +
stat_poly_eq(label.y = 0.9)+
my_theme+
theme(legend.position = "bottom")
#schnider plots====
wrangled_data%>%
ggplot(aes(x=moisture_persentage,y=attenuation_schneider))+
geom_point(aes(color=Depth,shape=matrix))+
geom_smooth(method=lm,color="#616161",formula = y ~ poly(x, 2))+
facet_wrap(vars(element))+
scale_x_continuous(expand = c(0,0),
limits = c(0,100),
name = "Moisture (%)")+
scale_y_continuous(expand = c(0,0),
limits = c(0,1),
name = "Cwet/Cdry")+
#geom_abline(aes(intercept=0, slope=1),linetype="dashed",)+
stat_poly_eq(use_label("eq")) +
#stat_poly_eq(label.y = 0.9)+
my_theme+
theme(legend.position = "bottom")
